<?php

namespace AdminBundle\Controller;



class SettingController extends AdminController
{
    /*
     * 个人信息
     */
    public function indexAction()
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }

        $data = $this->getApiData("ApiBundle:Admin/Auth:selfInformation");
        return $this->render('AdminBundle:Setting:index.html.twig',array("data"=>$data));
    }


    /*
     * 编辑个人信息
     */
    public function editInformationAction()
    {

        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }

        $data = $this->getApiData("ApiBundle:Admin/Auth:selfInformation");
        return $this->render("AdminBundle:Setting:editInformation.html.twig",array("data"=>$data));
    }

    /*
     * 修改密码
     */
    public function editPasswordAction()
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }
        return $this->render("AdminBundle:Setting:editPassword.html.twig");
    }


    /*
     * 企业属性
     */
    public function companyAttributeAction()
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAll("SELECT * FROM company_attribute WHERE 1 ORDER BY id DESC");
        return $this->render("AdminBundle:Setting:companyAttribute.html.twig",array("data"=>$data));
    }

    /*
     * 企业类别
     */
    public function companyCategoryAction()
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }
        $conn = $this->get("database_connection");
        $data = $conn->fetchAll("SELECT * FROM company_category WHERE 1 ORDER BY id DESC");

        return $this->render("AdminBundle:Setting:companyCategory.html.twig",array("data"=>$data));
    }


    /*
     * banner列表
     */
    public function bannerListAction()
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }
        return $this->render("AdminBundle:Setting:bannerList.html.twig");
    }

    /*
     * 编辑banner
     */

    public function editBannerAction($id)
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAssoc("SELECT * FROM banner WHERE id = '". $id ."'");

        if(empty($id)){
            $data = array("id"=>$id);
        }

        return $this->render("AdminBundle:Setting:editBanner.html.twig",array("data"=>$data));
    }

    /*
     * 注册协议
     */
    public function agreementAction()
    {
        if(!$this->get("session")->get("admin_id")){

            return $this->render('AdminBundle:Auth:login.html.twig');
        }
        $conn = $this->get("database_connection");

        $data = $conn->fetchAssoc("SELECT * FROM settings WHERE type = 2");

        return $this->render("AdminBundle:Setting:agreement.html.twig",array("data"=>$data));
    }
}
